```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ForkJoinPool并发编程指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6e8efb 0%, #4a6cf7 100%);
        }
        .code-block {
            background: #2d3748;
            color: #f8fafc;
            border-radius: 0.5rem;
            position: relative;
        }
        .code-block::before {
            content: attr(data-lang);
            position: absolute;
            top: 0;
            right: 1rem;
            color: rgba(255,255,255,0.5);
            font-size: 0.8rem;
            text-transform: uppercase;
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .feature-icon {
            width: 3rem;
            height: 3rem;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            margin-bottom: 1rem;
        }
        .dropdown-content {
            display: none;
            position: absolute;
            min-width: 160px;
            box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
            z-index: 1;
        }
        .dropdown:hover .dropdown-content {
            display: block;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 md:py-32 px-4">
        <div class="container mx-auto max-w-6xl">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <span class="inline-block bg-white bg-opacity-20 text-sm px-4 py-2 rounded-full mb-4">
                        <i class="fas fa-microchip mr-2"></i>Java并发编程
                    </span>
                    <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight">深入理解ForkJoinPool</h1>
                    <p class="text-xl opacity-90 mb-8">探索Java分治并行任务的强大执行框架</p>
                    <div class="flex space-x-4">
                        <a href="#overview" class="bg-white text-blue-600 px-6 py-3 rounded-lg font-medium hover:bg-opacity-90 transition duration-300">
                            <i class="fas fa-book-open mr-2"></i>开始阅读
                        </a>
                        <a href="#examples" class="border-2 border-white text-white px-6 py-3 rounded-lg font-medium hover:bg-white hover:bg-opacity-10 transition duration-300">
                            <i class="fas fa-code mr-2"></i>查看示例
                        </a>
                    </div>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <div class="relative w-full max-w-md">
                        <div class="absolute -top-6 -left-6 w-32 h-32 bg-blue-300 rounded-full opacity-20"></div>
                        <div class="absolute -bottom-6 -right-6 w-32 h-32 bg-purple-300 rounded-full opacity-20"></div>
                        <div class="relative bg-white bg-opacity-10 backdrop-filter backdrop-blur-lg p-8 rounded-xl border border-white border-opacity-20">
                            <div class="mb-6">
                                <div class="flex justify-between items-center mb-2">
                                    <span class="text-sm opacity-80">ForkJoinPool 工作原理</span>
                                    <span class="text-xs px-2 py-1 bg-white bg-opacity-20 rounded">动态</span>
                                </div>
                                <div class="h-2 bg-white bg-opacity-20 rounded-full overflow-hidden">
                                    <div class="h-full bg-white rounded-full" style="width: 70%;"></div>
                                </div>
                            </div>
                            <div class="grid grid-cols-2 gap-4">
                                <div class="bg-white bg-opacity-10 p-4 rounded-lg">
                                    <div class="text-2xl font-bold mb-1">Fork</div>
                                    <div class="text-sm opacity-80">任务拆分</div>
                                </div>
                                <div class="bg-white bg-opacity-10 p-4 rounded-lg">
                                    <div class="text-2xl font-bold mb-1">Join</div>
                                    <div class="text-sm opacity-80">结果合并</div>
                                </div>
                                <div class="bg-white bg-opacity-10 p-4 rounded-lg">
                                    <div class="text-2xl font-bold mb-1">Steal</div>
                                    <div class="text-sm opacity-80">工作窃取</div>
                                </div>
                                <div class="bg-white bg-opacity-10 p-4 rounded-lg">
                                    <div class="text-2xl font-bold mb-1">Pool</div>
                                    <div class="text-sm opacity-80">线程池管理</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Table of Contents -->
    <section class="py-12 bg-white">
        <div class="container mx-auto max-w-6xl px-4">
            <h2 class="text-3xl font-bold mb-8 text-center">内容导航</h2>
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                <a href="#overview" class="card-hover group p-6 border border-gray-200 rounded-lg hover:border-blue-500 transition duration-300">
                    <div class="feature-icon bg-blue-100 text-blue-600 group-hover:bg-blue-600 group-hover:text-white">
                        <i class="fas fa-info-circle text-xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-2">ForkJoinPool概述</h3>
                    <p class="text-gray-600">了解ForkJoinPool的背景、工作机制及其优势</p>
                </a>
                <a href="#comparison" class="card-hover group p-6 border border-gray-200 rounded-lg hover:border-purple-500 transition duration-300">
                    <div class="feature-icon bg-purple-100 text-purple-600 group-hover:bg-purple-600 group-hover:text-white">
                        <i class="fas fa-balance-scale text-xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-2">与传统线程池对比</h3>
                    <p class="text-gray-600">比较ForkJoinPool与传统线程池的差异与优势</p>
                </a>
                <a href="#examples" class="card-hover group p-6 border border-gray-200 rounded-lg hover:border-green-500 transition duration-300">
                    <div class="feature-icon bg-green-100 text-green-600 group-hover:bg-green-600 group-hover:text-white">
                        <i class="fas fa-code text-xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-2">实际应用示例</h3>
                    <p class="text-gray-600">学习如何使用RecursiveTask和RecursiveAction</p>
                </a>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <section class="py-16 bg-gray-50">
        <div class="container mx-auto max-w-6xl px-4">
            <div class="flex flex-col md:flex-row">
                <!-- Sidebar -->
                <div class="md:w-1/4 pr-8 mb-10 md:mb-0">
                    <div class="sticky top-8">
                        <div class="bg-white p-6 rounded-lg shadow-sm border border-gray-200">
                            <h3 class="font-semibold text-lg mb-4">目录</h3>
                            <ul class="space-y-2">
                                <li><a href="#overview" class="text-blue-600 hover:text-blue-800 transition duration-200 flex items-center"><i class="fas fa-chevron-right mr-2 text-xs"></i>1. ForkJoinPool概述</a></li>
                                <li class="ml-4"><a href="#background" class="text-gray-700 hover:text-blue-600 transition duration-200">1.1 背景</a></li>
                                <li class="ml-4"><a href="#mechanism" class="text-gray-700 hover:text-blue-600 transition duration-200">1.2 工作机制</a></li>
                                <li><a href="#comparison" class="text-blue-600 hover:text-blue-800 transition duration-200 flex items-center"><i class="fas fa-chevron-right mr-2 text-xs"></i>2. 与传统线程池对比</a></li>
                                <li class="ml-4"><a href="#thread-pool-model" class="text-gray-700 hover:text-blue-600 transition duration-200">2.1 线程池模型</a></li>
                                <li class="ml-4"><a href="#advantages" class="text-gray-700 hover:text-blue-600 transition duration-200">2.2 优势</a></li>
                                <li><a href="#examples" class="text-blue-600 hover:text-blue-800 transition duration-200 flex items-center"><i class="fas fa-chevron-right mr-2 text-xs"></i>3. ForkJoinPool的使用</a></li>
                                <li class="ml-4"><a href="#creation" class="text-gray-700 hover:text-blue-600 transition duration-200">3.1 基本创建</a></li>
                                <li class="ml-4"><a href="#forkjointask" class="text-gray-700 hover:text-blue-600 transition duration-200">3.2 ForkJoinTask</a></li>
                                <li><a href="#stealing" class="text-blue-600 hover:text-blue-800 transition duration-200 flex items-center"><i class="fas fa-chevron-right mr-2 text-xs"></i>4. 工作窃取机制</a></li>
                                <li><a href="#performance" class="text-blue-600 hover:text-blue-800 transition duration-200 flex items-center"><i class="fas fa-chevron-right mr-2 text-xs"></i>5. 性能优势</a></li>
                            </ul>
                        </div>
                        <div class="mt-6 bg-white p-6 rounded-lg shadow-sm border border-gray-200">
                            <h3 class="font-semibold text-lg mb-4">关键术语</h3>
                            <div class="space-y-3">
                                <div>
                                    <div class="font-medium text-blue-600">工作窃取 (Work Stealing)</div>
                                    <p class="text-sm text-gray-600">空闲线程从其他线程的任务队列中"窃取"任务执行的机制</p>
                                </div>
                                <div>
                                    <div class="font-medium text-blue-600">分治算法 (Divide and Conquer)</div>
                                    <p class="text-sm text-gray-600">将大问题分解为小问题，分别解决后再合并结果的算法策略</p>
                                </div>
                                <div>
                                    <div class="font-medium text-blue-600">递归任务 (Recursive Task)</div>
                                    <p class="text-sm text-gray-600">可以递归拆分的并行任务，可能有返回值(RecursiveTask)或无返回值(RecursiveAction)</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Content -->
                <div class="md:w-3/4">
                    <!-- Overview -->
                    <div id="overview" class="mb-16">
                        <h2 class="text-3xl font-bold mb-6 pb-3 border-b border-gray-200">1. ForkJoinPool概述</h2>
                        
                        <div id="background" class="mb-10">
                            <h3 class="text-2xl font-semibold mb-4 flex items-center">
                                <span class="mr-2">1.1</span> ForkJoinPool的背景
                                <span class="ml-auto text-sm bg-blue-100 text-blue-800 px-3 py-1 rounded-full">基础知识</span>
                            </h3>
                            <p class="mb-4">在传统的线程池模型中，我们通常通过<code class="bg-gray-100 px-2 py-1 rounded">ExecutorService</code>提交任务并等待结果。然而，这种方式处理并行任务时，当任务量较大时，可能会遇到性能瓶颈。特别是在需要大量小任务并发执行的情况下，传统的线程池管理机制会导致线程的创建与销毁频繁，增加了系统的开销。</p>
                            <div class="bg-blue-50 border-l-4 border-blue-500 p-4 mb-6">
                                <div class="flex">
                                    <div class="flex-shrink-0">
                                        <i class="fas fa-info-circle text-blue-500 mt-1"></i>
                                    </div>
                                    <div class="ml-3">
                                        <p class="text-sm text-blue-700">Java 7引入了<code class="bg-blue-100 px-1 py-0.5 rounded">ForkJoinPool</code>，专门用于处理可以分解为更小子任务的问题，显著提高了并行计算的效率。</p>
                                    </div>
                                </div>
                            </div>
                            <p>为了解决这个问题，<code class="bg-gray-100 px-2 py-1 rounded">ForkJoinPool</code>应运而生。它是Java 7引入的一个高效的并行任务执行框架，特别适合用来处理"大任务拆分成小任务"的问题。<code class="bg-gray-100 px-2 py-1 rounded">ForkJoinPool</code>的核心思想是通过"工作窃取算法"(Work Stealing)来减少线程切换开销，从而提高任务的执行效率。</p>
                        </div>

                        <div id="mechanism">
                            <h3 class="text-2xl font-semibold mb-4 flex items-center">
                                <span class="mr-2">1.2</span> ForkJoinPool的工作机制
                                <span class="ml-auto text-sm bg-purple-100 text-purple-800 px-3 py-1 rounded-full">核心技术</span>
                            </h3>
                            <p class="mb-4"><code class="bg-gray-100 px-2 py-1 rounded">ForkJoinPool</code>与传统的线程池的不同之处在于它专门设计用于处理"可分割任务"。它的工作流程大致如下：</p>
                            
                            <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
                                <div class="bg-white p-6 rounded-lg border border-gray-200 shadow-sm card-hover">
                                    <div class="text-blue-600 mb-3">
                                        <i class="fas fa-code-branch text-3xl"></i>
                                    </div>
                                    <h4 class="font-semibold text-lg mb-2">任务拆分</h4>
                                    <p class="text-gray-700">一个大的任务会被拆分成多个小任务。这个拆分的过程由<code class="bg-gray-100 px-1 py-0.5 rounded">fork()</code>方法实现。</p>
                                </div>
                                <div class="bg-white p-6 rounded-lg border border-gray-200 shadow-sm card-hover">
                                    <div class="text-green-600 mb-3">
                                        <i class="fas fa-tasks text-3xl"></i>
                                    </div>
                                    <h4 class="font-semibold text-lg mb-2">并行执行</h4>
                                    <p class="text-gray-700">小任务可以并行执行，从而充分利用多核CPU的优势。</p>
                                </div>
                                <div class="bg-white p-6 rounded-lg border border-gray-200 shadow-sm card-hover">
                                    <div class="text-purple-600 mb-3">
                                        <i class="fas fa-user-secret text-3xl"></i>
                                    </div>
                                    <h4 class="font-semibold text-lg mb-2">工作窃取</h4>
                                    <p class="text-gray-700">如果某个线程的任务执行完毕，它可以从其他线程的队列中窃取任务执行。这种工作窃取的方式可以避免线程在空闲时长时间等待，提高资源利用率。</p>
                                </div>
                                <div class="bg-white p-6 rounded-lg border border-gray-200 shadow-sm card-hover">
                                    <div class="text-yellow-600 mb-3">
                                        <i class="fas fa-project-diagram text-3xl"></i>
                                    </div>
                                    <h4 class="font-semibold text-lg mb-2">结果合并</h4>
                                    <p class="text-gray-700">通过<code class="bg-gray-100 px-1 py-0.5 rounded">join()</code>方法等待子任务完成并合并结果，形成最终输出。</p>
                                </div>
                            </div>

                            <!-- Mermaid Diagram -->
                            <div class="bg-white p-6 rounded-lg border border-gray-200 shadow-sm mb-6">
                                <h4 class="font-semibold text-lg mb-4 text-center">ForkJoinPool工作流程示意图</h4>
                                <div class="mermaid">
                                    graph TD
                                        A[主任务] --> B[调用fork()拆分任务]
                                        B --> C[子任务1]
                                        B --> D[子任务2]
                                        C --> E[子任务1结果]
                                        D --> F[子任务2结果]
                                        E --> G[调用join()合并结果]
                                        F --> G
                                        G --> H[最终结果]
                                        
                                        style A fill:#4a6cf7,color:white
                                        style B fill:#6e8efb,color:white
                                        style C fill:#8a63f7,color:white
                                        style D fill:#8a63f7,color:white
                                        style E fill:#4caf50,color:white
                                        style F fill:#4caf50,color:white
                                        style G fill:#ff9800,color:white
                                        style H fill:#f44336,color:white
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Comparison -->
                    <div id="comparison" class="mb-16">
                        <h2 class="text-3xl font-bold mb-6 pb-3 border-b border-gray-200">2. ForkJoinPool与传统线程池的对比</h2>
                        
                        <div id="thread-pool-model" class="mb-10">
                            <h3 class="text-2xl font-semibold mb-4">2.1 线程池的基本模型</h3>
                            <p class="mb-4">传统的线程池通过<code class="bg-gray-100 px-2 py-1 rounded">ExecutorService</code>管理任务的执行。通常来说，线程池会有固定大小的线程池来执行任务，任务被提交后会由线程池中的线程执行。然而，在任务执行时，如果任务本身比较复杂或者需要拆分成更小的子任务，线程池的执行效率会受到限制，因为每个线程都有一个任务队列，需要在任务队列中排队等待。任务队列在这种情况下可能会导致线程资源的浪费。</p>
                            
                            <div class="bg-white p-6 rounded-lg border border-gray-200 shadow-sm mb-6">
                                <h4 class="font-semibold text-lg mb-4 text-center">传统线程池任务队列模型</h4>
                                <div class="mermaid">
                                    graph LR
                                        T1[线程1] --> Q1[任务队列1]
                                        T2[线程2] --> Q2[任务队列2]
                                        T3[线程3] --> Q3[任务队列3]
                                        style T1 fill:#9e9e9e
                                        style T2 fill:#9e9e9e
                                        style T3 fill:#9e9e9e
                                        style Q1 fill:#e0e0e0
                                        style Q2 fill:#e0e0e0
                                        style Q3 fill:#e0e0e0
                                </div>
                            </div>
                        </div>

                        <div id="advantages">
                            <h3 class="text-2xl font-semibold mb-4">2.2 ForkJoinPool的优势</h3>
                            <p class="mb-4">相比传统的线程池，<code class="bg-gray-100 px-2 py-1 rounded">ForkJoinPool</code>有以下显著优势：</p>
                            
                            <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6">
                                <div class="bg-white p-6 rounded-lg border border-gray-200 shadow-sm card-hover">
                                    <div class="text-blue-600 mb-3">
                                        <i class="fas fa-sitemap text-3xl"></i>
                                    </div>
                                    <h4 class="font-semibold text-lg mb-2">高效的任务拆分与合并</h4>
                                    <p class="text-gray-700"><code class="bg-gray-100 px-1 py-0.5 rounded">ForkJoinPool</code>适合处理可以拆分成多个小任务的场景，尤其是递归计算任务。</p>
                                </div>
                                <div class="bg-white p-6 rounded-lg border border-gray-200 shadow-sm card-hover">
                                    <div class="text-green-600 mb-3">
                                        <i class="fas fa-exchange-alt text-3xl"></i>
                                    </div>
                                    <h4 class="font-semibold text-lg mb-2">工作窃取机制</h4>
                                    <p class="text-gray-700">线程可以窃取其他线程的任务来执行，避免空闲线程浪费资源。</p>
                                </div>
                                <div class="bg-white p-6 rounded-lg border border-gray-200 shadow-sm card-hover">
                                    <div class="text-purple-600 mb-3">
                                        <i class="fas fa-tachometer-alt text-3xl"></i>
                                    </div>
                                    <h4 class="font-semibold text-lg mb-2">更低的线程切换开销</h4>
                                    <p class="text-gray-700">由于任务的拆分和合并方式不同于传统线程池，<code class="bg-gray-100 px-1 py-0.5 rounded">ForkJoinPool</code>能够减少线程切换的开销，提高并发执行的效率。</p>
                                </div>
                            </div>
                            
                            <div class="bg-white p-6 rounded-lg border border-gray-200 shadow-sm">
                                <h4 class="font-semibold text-lg mb-4 text-center">ForkJoinPool工作窃取机制示意图</h4>
                                <div class="mermaid">
                                    graph LR
                                        T1[线程1] --> Q1[任务队列1]
                                        T2[线程2] --> Q2[任务队列2]
                                        T3[线程3] --> Q3[任务队列3]
                                        T2 -. 窃取 .-> Q1
                                        T3 -. 窃取 .-> Q2
                                        style T1 fill:#4a6cf7,color:white
                                        style T2 fill:#4a6cf7,color:white
                                        style T3 fill:#4a6cf7,color:white
                                        style Q1 fill:#8a63f7,color:white
                                        style Q2 fill:#8a63f7,color:white
                                        style Q3 fill:#8a63f7,color:white
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Examples -->
                    <div id="examples" class="mb-16">
                        <h2 class="text-3xl font-bold mb-6 pb-3 border-b border-gray-200">3. ForkJoinPool的使用</h2>
                        
                        <div id="creation" class="mb-10">
                            <h3 class="text-2xl font-semibold mb-4">3.1 ForkJoinPool的基本创建</h3>
                            <p class="mb-4">创建一个<code class="bg-gray-100 px-2 py-1 rounded">ForkJoinPool</code>非常简单，可以通过其构造方法或者<code class="bg-gray-100 px-2 py-1 rounded">ForkJoinPool.commonPool()</code>来获取一个公共池：</p>
                            
                            <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
                                <div class="code-block p-6" data-lang="java">
                                    <pre class="overflow-x-auto"><code class="text-sm language-java">// 创建一个具有4个线程的ForkJoinPool
ForkJoinPool forkJoinPool = new ForkJoinPool(4);</code></pre>
                                </div>
                                <div class="code-block p-6" data-lang="java">
                                    <pre class="overflow-x-auto"><code class="text-sm language-java">// 使用系统的公共线程池
ForkJoinPool commonPool = ForkJoinPool.commonPool();</code></pre>
                                </div>
                            </div>
                            
                            <p><code class="bg-gray-100 px-2 py-1 rounded">ForkJoinPool</code>通常通过指定线程池的大小来初始化。如果不指定，Java会使用一个默认的大小，通常是CPU核心数。</p>
                        </div>

                        <div id="forkjointask">
                            <h3 class="text-2xl font-semibold mb-4">3.2 ForkJoinTask的使用</h3>
                            <p class="mb-4"><code class="bg-gray-100 px-2 py-1 rounded">ForkJoinPool</code>的任务并不是普通的<code class="bg-gray-100 px-2 py-1 rounded">Runnable</code>或者<code class="bg-gray-100 px-2 py-1 rounded">Callable</code>任务，而是<code class="bg-gray-100 px-2 py-1 rounded">ForkJoinTask</code>任务。它是<code class="bg-gray-100 px-2 py-1 rounded">ForkJoinPool</code>的核心类，分为两种类型：</p>
                            
                            <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
                                <div class="bg-white p-6 rounded-lg border border-blue-200 shadow-sm card-hover">
                                    <div class="text-blue-600 mb-3">
                                        <i class="fas fa-arrow-circle-right text-3xl"></i>
                                    </div>
                                    <h4 class="font-semibold text-lg mb-2">RecursiveTask</h4>
                                    <p class="text-gray-700">用于有返回值的任务，适合计算密集型操作，如数学计算、数据处理等。</p>
                                </div>
                                <div class="bg-white p-6 rounded-lg border border-purple-200 shadow-sm card-hover">
                                    <div class="text-purple-600 mb-3">
                                        <i class="fas fa-play-circle text-3xl"></i>
                                    </div>
                                    <h4 class="font-semibold text-lg mb-2">RecursiveAction</h4>
                                    <p class="text-gray-700">用于无返回值的任务，适合执行并行操作而不需要返回结果的情况。</p>
                                </div>
                            </div>
                            
                            <h4 class="text-xl font-semibold mb-4 mt-8">3.2.1 RecursiveTask示例</h4>
                            <p class="mb-4"><code class="bg-gray-100 px-2 py-1 rounded">RecursiveTask</code>是有返回值的任务，可以用来处理计算密集型的任务。以下是一个使用<code class="bg-gray-100 px-2 py-1 rounded">RecursiveTask</code>的例子，计算斐波那契数列。</p>
                            
                            <div class="code-block p-6 mb-6" data-lang="java">
                                <pre class="overflow-x-auto"><code class="text-sm language-java">public class FibonacciTask extends RecursiveTask&lt;Long&gt; {
    private final long n;

    public FibonacciTask(long n) {
        this.n = n;
    }

    @Override
    protected Long compute() {
        if (n <= 1) {
            return n;
        }
        FibonacciTask f1 = new FibonacciTask(n - 1);
        f1.fork();  // 异步执行f1任务

        FibonacciTask f2 = new FibonacciTask(n - 2);
        long f2Result = f2.fork().join();  // 异步执行f2任务并等待结果

        return f1.join() + f2Result;  // 合并结果
    }

    public static void main(String[] args) {
        ForkJoinPool pool = new ForkJoinPool();
        FibonacciTask task = new FibonacciTask(10);
        long result = pool.invoke(task);  // 提交并等待结果
        System.out.println("Fibonacci(10) = " + result);
    }
}</code></pre>
                            </div>
                            
                            <div class="bg-blue-50 border-l-4 border-blue-500 p-4 mb-6">
                                <div class="flex">
                                    <div class="flex-shrink-0">
                                        <i class="fas fa-lightbulb text-blue-500 mt-1"></i>
                                    </div>
                                    <div class="ml-3">
                                        <p class="text-sm text-blue-700">在这个例子中，<code class="bg-blue-100 px-1 py-0.5 rounded">FibonacciTask</code>任务会将任务递归拆分为更小的子任务，直到达到基本情况(n <= 1)。拆分任务时，我们调用了<code class="bg-blue-100 px-1 py-0.5 rounded">fork()</code>方法来异步执行子任务，然后通过<code class="bg-blue-100 px-1 py-0.5 rounded">join()</code>方法等待结果并合并。</p>
                                    </div>
                                </div>
                            </div>
                            
                            <h4 class="text-xl font-semibold mb-4 mt-8">3.2.2 RecursiveAction示例</h4>
                            <p class="mb-4">如果任务不需要返回值，可以使用<code class="bg-gray-100 px-2 py-1 rounded">RecursiveAction</code>。以下是一个使用<code class="bg-gray-100 px-2 py-1 rounded">RecursiveAction</code>的例子，计算数组的部分和。</p>
                            
                            <div class="code-block p-6 mb-6" data-lang="java">
                                <pre class="overflow-x-auto"><code class="text-sm language-java">public class SumTask extends RecursiveAction {
    private final int[] array;
    private final int start, end;
    private static final int THRESHOLD = 1000;  // 拆分的阈值

    public SumTask(int[] array, int start, int end) {
        this.array = array;
        this.start = start;
        this.end = end;
    }

    @Override
    protected void compute() {
        if (end - start <= THRESHOLD) {
            // 如果任务大小小于阈值，直接执行
            long sum = 0;
            for (int i = start; i < end; i++) {
                sum += array[i];
            }
            System.out.println("Sum: " + sum);
        } else {
            // 否则拆分任务
            int middle = (start + end) / 2;
            SumTask leftTask = new SumTask(array, start, middle);
            SumTask rightTask = new SumTask(array, middle, end);
            leftTask.fork();  // 异步执行左任务
            rightTask.fork();  // 异步执行右任务
            leftTask.join();  // 等待左任务完成
            rightTask.join();  // 等待右任务完成
        }
    }

    public static void main(String[] args) {
        int[] array = new int[10000];
        Arrays.fill(array, 1);  // 填充数组，所有元素为1
        ForkJoinPool pool = new ForkJoinPool();
        SumTask task = new SumTask(array, 0, array.length);
        pool.invoke(task);  // 提交并等待结果
    }
}</code></pre>
                            </div>
                            
                            <div class="bg-yellow-50 border-l-4 border-yellow-500 p-4 mb-6">
                                <div class="flex">
                                    <div class="flex-shrink-0">
                                        <i class="fas fa-exclamation-triangle text-yellow-500 mt-1"></i>
                                    </div>
                                    <div class="ml-3">
                                        <p class="text-sm text-yellow-700">注意：在实际应用中，应该避免像斐波那契示例那样对每个小任务都进行拆分，这会创建大量的小任务反而降低性能。通常应该设置一个合理的阈值，当任务规模小于阈值时直接计算，而不是继续拆分。</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Work Stealing -->
                    <div id="stealing" class="mb-16">
                        <h2 class="text-3xl font-bold mb-6 pb-3 border-b border-gray-200">4. ForkJoinPool的工作窃取机制</h2>
                        <p class="mb-4"><code class="bg-gray-100 px-2 py-1 rounded">ForkJoinPool</code>的一个重要特点是其工作窃取机制。即如果某个线程完成了自己的任务，它会尝试从其他线程的队列中窃取任务来执行，以此提高资源的利用率和任务的执行效率。在默认情况下，<code class="bg-gray-100 px-2 py-1 rounded">ForkJoinPool</code>使用一个双端队列(Deque)来管理任务。每个线程从自己的队列中弹出任务来执行，如果队列为空，它会从其他线程的队列尾部窃取任务。通过这种方式，<code class="bg-gray-100 px-2 py-1 rounded">ForkJoinPool</code>能够最大化地利用所有可用的CPU核心。</p>
                        
                        <div class="bg-white p-6 rounded-lg border border-gray-200 shadow-sm mb-6">
                            <div class="mermaid">
                                graph LR
                                    subgraph 线程1
                                    T1 --> Q1[任务1-1, 任务1-2, 任务1-3]
                                    end
                                    
                                    subgraph 线程2
                                    T2 --> Q2[任务2-1, 任务2-2]
                                    end
                                    
                                    subgraph 线程3
                                    T3 --> Q3[任务3-1]
                                    end
                                    
                                    T3 -. 从线程1窃取任务1-3 .-> Q1
                                    style T1 fill:#4a6cf7,color:white
                                    style T2 fill:#4a6cf7,color:white
                                    style T3 fill:#4a6cf7,color:white
                                    style Q1 fill:#8a63f7,color:white
                                    style Q2 fill:#8a63f7,color:white
                                    style Q3 fill:#8a63f7,color:white
                            </div>
                        </div>
                        
                        <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                            <div class="bg-white p-6 rounded-lg border border-gray-200 shadow-sm card-hover">
                                <div class="text-blue-600 mb-3">
                                    <i class="fas fa-random text-3xl"></i>
                                </div>
                                <h4 class="font-semibold text-lg mb-2">双端队列管理</h4>
                                <p class="text-gray-700">每个线程维护自己的双端队列，从头部取任务执行，从尾部窃取任务。</p>
                            </div>
                            <div class="bg-white p-6 rounded-lg border border-gray-200 shadow-sm card-hover">
                                <div class="text-green-600 mb-3">
                                    <i class="fas fa-users text-3xl"></i>
                                </div>
                                <h4 class="font-semibold text-lg mb-2">负载均衡</h4>
                                <p class="text-gray-700">工作窃取机制自动平衡各线程的工作负载，减少空闲时间。</p>
                            </div>
                            <div class="bg-white p-6 rounded-lg border border-gray-200 shadow-sm card-hover">
                                <div class="text-purple-600 mb-3">
                                    <i class="fas fa-bolt text-3xl"></i>
                                </div>
                                <h4 class="font-semibold text-lg mb-2">高效并发</h4>
                                <p class="text-gray-700">减少了线程间的竞争和同步开销，提高CPU利用率。</p>
                            </div>
                        </div>
                    </div>

                    <!-- Performance -->
                    <div id="performance" class="mb-16">
                        <h2 class="text-3xl font-bold mb-6 pb-3 border-b border-gray-200">5. ForkJoinPool的性能优势</h2>
                        <p class="mb-6">与传统线程池相比，<code class="bg-gray-100 px-2 py-1 rounded">ForkJoinPool</code>具有以下几个性能优势：</p>
                        
                        <div class="bg-white p-6 rounded-lg border border-gray-200 shadow-sm mb-8">
                            <div class="mermaid">
                                pie
                                    title ForkJoinPool性能优势
                                    "减少线程切换" : 35
                                    "工作窃取机制" : 40
                                    "递归任务优化" : 25
                            </div>
                        </div>
                        
                        <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                            <div class="bg-white p-6 rounded-lg border border-gray-200 shadow-sm card-hover">
                                <h4 class="font-semibold text-lg mb-2">减少线程切换</h4>
                                <p class="text-gray-700">通过任务拆分与合并，减少了线程间的竞争和切换，降低了上下文切换的开销。</p>
                            </div>
                            <div class="bg-white p-6 rounded-lg border border-gray-200 shadow-sm card-hover">
                                <h4 class="font-semibold text-lg mb-2">高效的工作窃取</h4>
                                <p class="text-gray-700">通过工作窃取机制，<code class="bg-gray-100 px-1 py-0.5 rounded">ForkJoinPool</code>能够最大化利用CPU资源，避免部分线程空闲浪费。</p>
                            </div>
                            <div class="bg-white p-6 rounded-lg border border-gray-200 shadow-sm card-hover">
                                <h4 class="font-semibold text-lg mb-2">优化递归任务的处理</h4>
                                <p class="text-gray-700"><code class="bg-gray-100 px-1 py-0.5 rounded">ForkJoinPool</code>非常适合处理递归计算或分治算法任务，它能够通过合理的任务拆分和合并，充分发挥并行计算的优势。</p>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Summary -->
                    <div class="bg-blue-50 rounded-lg p-8 mb-16">
                        <h3 class="text-2xl font-semibold mb-4 text-blue-800">关键要点总结</h3>
                        <ul class="space-y-3 text-blue-900">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-600 mt-1 mr-2"></i>
                                <span><code class="bg-blue-100 px-1 py-0.5 rounded">ForkJoinPool</code>是Java中专门为分治任务设计的并行执行框架，适合处理可以递归拆分的任务</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-600 mt-1 mr-2"></i>
                                <span>通过<code class="bg-blue-100 px-1 py-0.5 rounded">fork()</code>拆分任务，<code class="bg-blue-100 px-1 py-0.5 rounded">join()</code>合并结果的工作模式，可以有效利用多核CPU</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-600 mt-1 mr-2"></i>
                                <span>工作窃取机制(Work Stealing)是<code class="bg-blue-100 px-1 py-0.5 rounded">ForkJoinPool</code>的核心优势，能够自动平衡线程负载</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-600 mt-1 mr-2"></i>
                                <span>使用<code class="bg-blue-100 px-1 py-0.5 rounded">RecursiveTask</code>处理有返回值的任务，<code class="bg-blue-100 px-1 py-0.5 rounded">RecursiveAction</code>处理无返回值的任务</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-600 mt-1 mr-2"></i>
                                <span>在实际应用中应设置合理的阈值，避免过度拆分导致性能下降</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8">
        <div class="container mx-auto max-w-6xl px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-semibold text-white mb-2">技术小馆</h3>
                    <a href="http://www.yuque.com/jtostring" class="text-blue-400 hover:text-blue-300 transition duration-200">
                        <i class="fas fa-external-link-alt mr-1"></i>http://www.yuque.com/jtostring
                    </a>
                </div>
                <div class="flex space-x-4">
                    <a href="#" class="w-10 h-10 rounded-full bg-gray-800 flex items-center justify-center hover:bg-blue-600 transition duration-200">
                        <i class="fab fa-github"></i>
                    </a>
                    <a href="#" class="w-10 h-10 rounded-full bg-gray-800 flex items-center justify-center hover:bg-blue-500 transition duration-200">
                        <i class="fab fa-twitter"></i>
                    </a>
                    <a href="#" class="w-10 h-10 rounded-full bg-gray-800 flex items-center justify-center hover:bg-red-600 transition duration-200">
                        <i class="fab fa-youtube"></i>
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-sm text-gray-500 text-center">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            },
            pie: {
                textPosition: 0.8,
                useWidth: 900,
                useMaxWidth: true
            }
        });
        
        // 平滑滚动
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>
```